package com.zj.study.utils.validation.validator.repeat;

import com.zj.study.utils.validation.annotation.ValidateSupport;
import java.util.Arrays;
import java.util.HashSet;
import org.springframework.lang.NonNull;

/**
 * @author 谭耀飞
 * @since 2020.12.0
 */
@ValidateSupport(Object[].class)
public class NotRepeatValidatorForArray extends AbstractNotRepeatValidator<Object[]> {

  @Override
  public boolean compare(@NonNull Object[] value) {
    return value.length < 2 || new HashSet<>(Arrays.asList(value)).size() == value.length;
  }

}
